package bairui.international.console.web.controller.prize.nine;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;
import com.querydsl.core.BooleanBuilder;

import bairui.international.model.domain.jpa.QTB_PrizeItem;
import bairui.international.model.domain.jpa.TB_PrizeItem;
import bairui.international.service.Service_PrizeItem;

/**
 *
 * 详情
 *
 * @generated
 * 
 * @see STest_C_Prize_Nine_Detail_ItemPage 测试
 *
 */
@Controller
public class C_Prize_Nine_Detail_ItemPage
 extends SC_Prize_Nine_Detail_ItemPage 
{
	
	@Autowired private Service_PrizeItem service_PrizeItem;
	
	/**
	 * 奖品列表
	 */
	@Action(ItemPage.class)
	@GetMapping(value=ItemPage.RequestMappingValue, consumes=MediaType.APPLICATION_JSON_VALUE)
	public @FomatOutput @ResponseBody Object itemPage(
		HttpServletRequest request, 
		@PathVariable(name=ItemPage.PathVariableName.Id) long id
	) throws Exception {
		org.springframework.data.domain.Page<TB_PrizeItem> page = service_PrizeItem.page(
				it->filter(it, id, request), 
				ItemPage.Output.page(request), 
				it->sort(it, request)
			);
		page.forEach(it->{
			it.setFileUrl(C_Prize_Nine_ItemManage_ShowImg.ShowImg.Operate(id, it.getId()).getUrl());
		});
		//
		return ItemPage.Output.output(
				page
			);
	}
	
	/*
	 * 过滤
	 */
	static BooleanBuilder filter(QTB_PrizeItem it, long prizeId, HttpServletRequest request){
		return ItemPage.Filter.query()
			.and(it.prize.id.eq(prizeId));
	}
	
	/*
	 * 排序
	 */
	static Sort sort(QTB_PrizeItem it, HttpServletRequest request){
		return ItemPage.Output.sort(it, request);
	}
	
	

}
